/* eslint valid-jsdoc: "off" */

'use strict';
const path  = require('path');
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1678887389313_4136';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  config.sequelize = {
    dialect: 'mysql', //数据库类型
    database: 'homepage' , //数据库名称
    host: '120.48.87.115', //数据库ip地址
    port: '3306',      //数据库端口
    username: 'root',   //数据库用户名
    password: 'mdghost2016',   //数据库密码
    timezone: '+08:00',
    define: {  // model的全局配置
      timestamps: true,   // 添加create,update,delete时间戳
      paranoid: true,   // 添加软删除
      freezeTableName: true,  // 防止修改表名为复数
      underscored: false  // 防止驼峰式字段被默认转为下划线
    },
    // 打印日志
    logging: true,
    // 时间格式化
    dialectOptions: {
      dateStrings: true,
      typeCast: true
    }
  } 
  config.jwt = { //jwt加盐以及设置过期时间
    secret: 'mdghost',
    expiresIn:'1h'
  };
  config.view = {
      mapping: {'.html': 'ejs'} //左边写成.html后缀，会自动渲染.html文件
  };
  config.security = {
    // 关闭 csrf
    csrf: {
      enable: false,
    },
     // 跨域白名单
    domainWhiteList: [],
  };
  // 允许跨域的方法
  config.cors = {
    origin: '*',
    allowMethods: 'GET, PUT, POST, DELETE, PATCH'
  };
  config.uploadDir = 'app/public/img';
  config.multipart = {
    // mode: 'file',
    // fileSize: 1048576000,
    // whitelist: [ '.txt', '.png', '.jpg' ],
    mode: 'stream',
    fileModeMatch: /(\/upload)$/,
    fileSize: "500mb",
    whitelist: [".txt", ".png", ".jpg",'.mp4'],
  };
  // 文件静态路径
  config.static = {
    prefix: '/app/public', //访问前缀
    dir: path.join(appInfo.baseDir, 'app/public'), 
    dynamic: true, 
    preload: false,
    maxAge: 31536000, 
    buffer: true, 
 };
  return {
    ...config,
    ...userConfig,
  };
};
